// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <streambuf>
#include <fstream>
#include <iostream>
#include <winsock.h>
#include <map>
#include <vector>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <algorithm>
#include <mmsystem.h>
using namespace std;

extern "C"
{
#include "Language\lua.h"
#include "language\lualib.h"
#include "language\lauxlib.h"
#include "language\ldebug.h"
#include "database\sqlite3.h"
}

#include "utilities\Thread.h"
#include "utilities\Mutex.h"
#include "utilities\Lock.h"
#include "utilities\ThreadObject.h"

#include "FileSystem\File.h"
#include "SysRoot\SystemRoot.h"

/* constants */

#define		COLOUR_BLACK			0
#define		COLOUR_BLUE				1
#define		COLOUR_GREEN			2
#define		COLOUR_CYAN				3
#define		COLOUR_RED				4
#define		COLOUR_MAGENTA			5
#define		COLOUR_BROWN			6
#define		COLOUR_LIGHTGREY		7
#define		COLOUR_GREY				8
#define		COLOUR_LIGHTBLUE		9
#define		COLOUR_LIGHTGREEN		10
#define		COLOUR_LIGHTCYAN		11
#define		COLOUR_LIGHTRED			12
#define		COLOUR_LIGHTMAGENTA		13
#define		COLOUR_YELLOW			14
#define		COLOUR_WHITE			15

#define		PACKET_AUTHENTICATE		1
#define		PACKET_AUTHRESPONSE		2
#define		PACKET_VDOREQUPDATE		3
#define		PACKET_VDOFULLSCREEN	4
#define		PACKET_VDOOPEN			5
#define		PACKET_VDOCHANGES		6
#define		PACKET_VDOCONFIRMREC	7
#define		PACKET_KEYPRESS			17
#define		PACKET_COMMANDPRESS		18
#define		PACKET_SHUTDOWNCLIENT	255
#define		PACKET_KEEPALIVE		254

#define		VDO_CONSOLE				1
#define		VDO_TEXT				2
#define		VDO_GRAPHIC				3
#define		VDO_TEXTSTREAM			4

#define		CONNECTION_CLIENT		1
#define		CONNECTION_FILESYS		2
#define		CONNECTION_SYNCFS		3
#define		CONNECTION_SYNCDB		4

#define		VCHANGE_LINEOUT			1

#define		PRIORITY_HIGHEST		0
#define		PRIORITY_HIGH			1
#define		PRIORITY_AVERAGE		2
#define		PRIORITY_LOW			3
#define		PRIORITY_LOWEST			4
#define		PRIORITY_PAUSE			5


#define		PRODUCT_NAME			"AdiOS Server"
#define		PRODUCT_VERSION			"v1.00.000"
#define		PRODUCT_PORT			4321
#define		MAX_CONNECTIONS			10
#define		SYSTEM_DEBUG_LEVEL		5

// client can support multiple connections to the server of differing types, e.g. tabs.  Ideally these will be per process run
#define		CLIENT_SUPPORTS_TEXT	1
#define		CLIENT_SUPPORTS_GUI		2
#define		CLIENT_SUPPORTS_HTML	4
#define		CLIENT_SUPPORTS_BINARY	8


/* below the constant filenames and folders */
#define		USER_DATABASE_NAME		"system_users.db"
#define		FS_DATABASE_NAME		"system_fs.db"
#define		DATABASE_FOLDER			"databases"
#define		CORE_FOLDER				"core"
#define		MAX_FILE_QUERY_LEN		2048
#define		MAX_FILE_REVISIONS		5


/* file system return values */

#define		FS_NOERROR				0
#define		FS_FILENOTFOUND			-1
#define		FS_PERMISSIONSERR		-2
#define		FS_FILESYSTEMERR		-3
#define		FS_NOREVISIONFORFILE	-4

/* object permission constants */
#define		PERMISSION_READ			1
#define		PERMISSION_LIST			2
#define		PERMISSION_WRITE		4
#define		PERMISSION_DELETE		8
#define		PERMISSION_SECURITY		16

// TODO: reference additional headers your program requires here
void encrypt(unsigned int num_rounds, unsigned int v[2], unsigned int const k[4]);
void decrypt(unsigned int num_rounds, unsigned int v[2], unsigned int const k[4]);

// vm static methods
string os_LoadFile(const char* folder, const char* filename);

// SYSTEM ROOT OBJECT AND ACCESSORS //
static CSysRoot*	sysRoot;	// there will be only one!